<?php
	require_once(dirname(dirname(__DIR__)) . '/core.php');

?>
	<h2 class="ibar_plugin_title"><span class="ibar_plugin_name">最近查看</span></h2>
	<div class="ibar_plugin_content" style="height: 450px; overflow-y: auto;">
		<?php
			$recent = cookie('recent_goods') or $recent = '[]';
			$recent = json_decode($recent,true);
		?>
		<div class="ibar-history-head">共 <span><?php echo count($recent)?></span>	件商品<a href="javascript:;" id="ibar-btn-clearhistory">清空</a>
		</div>
		<div class="ibar-moudle-product">
			<?php
				foreach($recent as $key => $val){
					$ginfo = Model()->table('goods')->find($val);
					$gminfo = Model()->table('goods_common')->where(array('goods_commonid' => $ginfo['goods_commonid']))->find();
					$sinfo = Model()->table('store')->find($ginfo['store_id']);
			?>
			<div class="imp_item">
				<a href="/shop/index.php?act=goods&goods_id=<?php echo $ginfo['goods_id']?>" title="" target="_blank" class="pic">
					<img src="/data/upload/shop/store/goods/<?php echo $sinfo['store_id']?>/<?php echo $ginfo['goods_image']?>" width="100" height="100">
				</a>
				<p class="tit"><a href="/shop/index.php?act=goods&goods_id=<?php echo $ginfo['goods_id']?>" title="" target="_blank"><?php echo $ginfo['goods_name']?></a>
				</p>
				<p class="price"><em>¥</em><?php echo $ginfo['goods_price']?></p><a href="javascript:;" target="_blnak" class="imp-addCart" key="<?php echo $ginfo['goods_id']?>" type="product" img="http://p0.jmstatic.com/product/000/507/507660_std/507660_100_100.jpg">加入购物车</a>

				<a data-id=<?php echo $ginfo['goods_id'] ?> href="javascript:;" class="_remove"
				   style="line-height: 27px;display: inline-block;vertical-align: top;float: right;width: 20px;color: red;font-weight: bold;"> x </a>
			</div>

			<?php
				}
			?>

		</div>
		<script>
			$('.imp_item ._remove').click(function () {
				var id = $(this).attr('data-id');
				var _this = $(this);
				$.get('/shop/?act=seccode&op=remove_recent', {id: id}, function () {
					_this.parents('.imp_item').fadeOut();
					var his_num = $('.ibar-history-head span').text();
					his_num = his_num - 1;
					if(his_num<=0){ his_num = 0;}
					$('.ibar-history-head span').text(his_num);
				});
			})
			$('.ibar_plugin_content').height($(window).height() - 50);
			$('#ibar-btn-clearhistory').click(function(){
				$('.imp_item').fadeOut();
				$('.ibar-history-head').html('共0件商品 <a href="javascript:;" id="ibar-btn-clearhistory">清空</a>');
				$.get('/shop/index.php?act=seccode&op=remove_recent');
			});
		</script>
	</div>
</div>